<?

function getMavro($summ, $kurs)
{
	return round($summ / $kurs, 4);
}

function getFloat($n)
{
	return floatval(str_replace(" ", "", str_replace(",", ".", trim($n))));
}

function dateToDb($date)
{
	list($y, $m, $d) = explode("-", $date);
	$m = intval($m);
	$d = intval($d);
	return $y."-".($m < 10 ? "0" : '') .$m.'-'.($d < 10 ? "0" : '') .$d;
}

function getLastVersion()
{
	$version = null;
	$d = opendir(SEFLDIR.'version');
	$file = null;
	$last_time = 0;
	while($f = readdir($d))
	{
		if($f == '.' || $f == '..') continue;
		if(is_file(SEFLDIR.'version/'.$f))
		{
			$t = filemtime(SEFLDIR.'version/'.$f);
			if($t > $last_time)
			{
				$version = $f;
				$last_time = $t;
			}
		}
	}
	closedir($d);
	return $version;
}

function createHi($num)
{
	$num = intval($num);
	return (strlen($num) - 1).$num;
}

function hiLevel($hi)
{
	$level = 0;
	if($hi != '')
	{
		$arr = explode(".", $hi);
		$level = count($arr);
	}
	return $level;
}

function getParentHi($hi, $level = null)
{
	$arr = explode('.', $hi);
	if(!$level)
	{
		$level = count($arr) - 1;
	}
	$arr2 = array_slice($arr, 0, $level);
	return implode('.', $arr2);
}

function getPrintDate($date)
{
	$arr = explode("-", $date);
	return @$arr[2].(@$arr[2] ? '.' : '').@$arr[1].(@$arr[1] ? '.' : '').$arr[0];
}


